//
//  FeaturedTableView.m
//  ZooNgonDoiOS
//
//  Created by Trung sound on 7/5/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "FeaturedTableView.h"
#import "ZooSpotBean.h"
#import "DetailViewController.h"

@implementation FeaturedTableView
@synthesize spotDetailDelegate;

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _arName = [NSMutableArray arrayWithObjects:@"Sumo BBQ", @"Kichi kichi", nil];
        _arAddress = [NSMutableArray arrayWithObjects:@"266 Doi Can - Ba Dinh", @"80 Ton Duc Thang - Dong Da", nil];
        _arDistance = [NSMutableArray arrayWithObjects:@"5km", @"7km", nil]; 
        self.delegate = self;
        self.dataSource = self;
        [self setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:IMG_VIEW_BACKGROUND]]];
    }
    return self;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
        // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
        // Return the number of rows in the section.
    return [_arName count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"MyCell";
    ListItemTableViewCell *cellView = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    _arName = [NSMutableArray arrayWithObjects:@"Sumo BBQ", @"Kichi kichi", nil];
    _arAddress = [NSMutableArray arrayWithObjects:@"266 Doi Can - Ba Dinh", @"80 Ton Duc Thang - Dong Da", nil];
    _arDistance = [NSMutableArray arrayWithObjects:@"5km", @"7km", nil]; 
    if (cellView == nil){
        cellView = [[ListItemTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
        cellView.tag = 1;
    } 
    
    [cellView.vImgItem setImage:nil];
    cellView.lbNameItem.text = [_arName objectAtIndex:indexPath.row];
    cellView.lbAddress.text = [_arAddress objectAtIndex:indexPath.row];
    cellView.lbDistance.text = [_arDistance objectAtIndex:indexPath.row];
    
    return cellView;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ZooSpotBean *_mSpot = [[ZooSpotBean alloc] init];
    _mSpot.name = @"abc";
    
    if (spotDetailDelegate != nil) {
        [spotDetailDelegate pushToSpotDetailScreen:_mSpot];
    }
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 130;
}
@end
